#ifndef _STREAMSOCKET_HPP_
#define _STREAMSOCKET_HPP_

#include "types.hpp"
#include "jhdefs.hpp"
#include "net/SocketDefs.hpp"
#include "net/Socket.hpp"
#include "net/SocketImpl.hpp"
#include "net/SocketAddress.hpp"
#include "net/IPAddress.hpp"

#include "stdlib/timespan.hpp"
using JHCPP::stdlib::CTimeSpan;

NET_NAMESPACE_BEGIN

/*
* TCP stream socket
*/
class CStreamSocket : public CSocket
{
public:
	CStreamSocket();
	explicit CStreamSocket(const CSocketAddress& address);
	explicit CStreamSocket(CIPAddress::Family family);
	CStreamSocket(const CSocket& socket);
	virtual ~CStreamSocket();
	CStreamSocket& operator = (const CSocket& socket);

	void connect(const CSocketAddress& address);
	void connect(const CSocketAddress& address, const CTimeSpan& timeout);
	void connectNB(const CSocketAddress& address);
	void shutdownReceive();
	void shutdownSend();
	void shutdown();
	int sendBytes(const void* buffer, int length, int flags = 0);
	//int sendBytes(CFIFOBuffer& buffer);
	int receiveBytes(void* buffer, int length, int flags = 0);
	//int receiveBytes(CFIFOBuffer& buffer);
	void sendUrgent(unsigned char data);
	CStreamSocket(CSocketImpl* pImpl);

private:
	enum
	{
		BUFFER_SIZE = 1024
	};

	friend class CServerSocket;
	friend class CSocketIOS;
};

NET_NAMESPACE_END

#endif
